package org.kimoji.search.web;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.kimoji.entity.Category;
import org.kimoji.entity.biz.ItemBiz;
import org.kimoji.global.service.GlobalService;
import org.kimoji.search.service.SearchService;
import org.kimoji.show.service.ShowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class SearchController {

	@Autowired
	private SearchService searchService;
	@Autowired
	private GlobalService globalService;
	@Autowired
	private ShowService showService;
	
	@RequestMapping(value="search/{type}/{keyword}")
	public String index(@PathVariable @ModelAttribute String type,@PathVariable @ModelAttribute String keyword,ModelMap modelMap){
		
		List<Category> categories = globalService.showCategory();
		modelMap.put("categories", categories);
		if("video".equals(type)){
			
			List<ItemBiz> items = showService.show(1, null, 1, keyword);
			modelMap.put("items", items);
			searchService.searchItem();
			return "search";
		}else{
			
			return "album/search";
		}
			
	}
	
	@RequestMapping(value="search/{type}/{keyword}/{category}/{order}/{index}")
	@ResponseBody
	public Object search(@PathVariable String type,@PathVariable String keyword,@PathVariable String category,@PathVariable String order,@PathVariable int index){
		List<ItemBiz> items = showService.show(1, null, 1, keyword);
		return items;
	}
	
}
